package managers.conversationManager.services;

import managers.conversationManager.ConversationManager;
import managers.conversationManager.GenericSocket;
import managers.messengerManager.services.Service;
import utils.StackTracePrinter;

public class FileTransferListeningService extends Service {

	
	public FileTransferListeningService() {
		super("FileTransferListening");
	}

	@Override
	public void run() {
		listenToFileTransferRequests();
	}
	
	private void listenToFileTransferRequests() {
		try {
			while (true) {
				GenericSocket s = ConversationManager.getSharedInstance().getProtocol().acceptFileTransferRequest();
				try {
					new ReceiveFile(s).start();
				} catch (Exception e) {
					StackTracePrinter.print(e);
					System.out.println("Error accepting incoming file transfer.");
				}
			}
		} catch (Exception e) {
			//buttami fuori
		}
	}
	
}
